#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "testutilities.h"
#include <assert.h>



int testOutpost(struct gameState *g, FILE *fp, int count){
	int currentPlayer = g->whoseTurn;

	//if(count > 3200){
	//	printGameState(g, fp);
	//}

	if(g->handCount[g->whoseTurn] > 0){
		g->hand[g->whoseTurn][0] = outpost;
	//	if(count > 900){
	//		printGameState(g, fp);
	//	}
	
		if(playCard(0, -1, -1, -1, g) >= 0){
			//if(count > 900){
			//printGameState(g, fp);
			//}			//printf("outpost played");
			assert(g->outpostPlayed > 0);
			endTurn(g);
			assert(g->whoseTurn == currentPlayer);
			//if(count > 900){
			//printGameState(g, fp);
			//}
			if(g->handCount[g->whoseTurn] <=3){
				return 0;
			}
			assert(g->handCount[g->whoseTurn] <= 3);
		}
	}
	
	return 1;
}

int main(int argc, char** argv){
	int tests = 1000;
	int seed = 1;

	if(argc > 1){
		tests = atoi(argv[1]);
	}
	if(argc > 2){
		seed = atoi(argv[2]);
	}
	prepRandom(1, seed);
	FILE *fp;
	char *fileName = "outpost.out";
	fp = fopen(fileName, "w+");
	if(fp == NULL){
		perror("Error");
		exit(0);
	}

	printf("Testing outpost tests: %d seed: %d\n", tests, seed);
	int i;
	for(i=0; i < tests; i++){
		struct gameState *g = newGame();
		makeRandomGameState(g);
		if(testOutpost(g, fp, i) ==0){
			printf("Test Failed\n");
			free(g);
			fclose(fp);
			return 0;
		}
		free(g);
	}
	printf("Test Complete\n");
	fclose(fp);

return 0;
}
